<%= render Admin::ContainerComponent.new do %>
  <%= render Admin::HeadingComponent.new(t(".title")) %>

  <%= render Admin::ContentComponent.new do %>
    <%= render Admin::Tables::TableComponent.new do |table| %>
      <% table.with_header "Date" %>
      <% table.with_header "Type" %>
      <% table.with_header "Description" %>
      <% table.with_header "Amount", align: :right %>
      <% table.with_header align: :right do %>
        <span class="sr-only">Actions</span>
        <%= render Admin::IconButtonComponent.new("Add expense", new_admin_transaction_path, icon: "plus_sm") %>
      <% end %>

      <% @transactions.each do |transaction| %>
        <% table.with_row do |row| %>
          <% row.with_cell primary: true do %>
            <%= transaction.occurred_on.to_formatted_s(:long) %>
          <% end %>

          <% row.with_cell do %>
            <%= transaction.transaction_type.humanize %>
          <% end %>

          <% row.with_cell do %>
            <% if transaction.url.present? %>
              <%= render Admin::BasicLinkComponent.new(transaction.description, transaction.url, external: true) %>
            <% else %>
              <%= transaction.description %>
            <% end %>
          <% end %>

          <% row.with_cell align: :right do %>
            <%= number_to_currency(transaction.amount) %>
          <% end %>

          <% row.with_cell align: :right do %>
            <%= render Admin::BasicLinkGroupComponent.new do |group| %>
              <% group.with_link "Edit", edit_admin_transaction_path(transaction) %>
              <% group.with_link "Delete", admin_transaction_path(transaction), data: {turbo_method: :delete, turbo_confirm: t(".delete_confirmation")} %>
            <% end %>
          <% end %>
        <% end %>
      <% end %>
    <% end %>
  <% end %>
<% end %>
